package com.wzy.pachong;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;

import javax.swing.JEditorPane;

import org.apache.commons.collections.map.HashedMap;

public class MyJEditorPane extends JEditorPane{

	public static final String ua = "User-Agent:Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 MobileSafari/537.36";

	public static Map<String,String> head = new HashedMap();
	
//	static {
//		head.put("Accept", "image/webp,*/*;q=0.8");
//		head.put("Accept-Encoding", "gzip, deflate, sdch");
//		head.put("Accept-Language", "zh-CN,zh;q=0.8,en;q=0.6");
//		head.put("Cache-Control", "no-cache");
//		head.put("Connection", "keep-alive");
//		head.put("Host", "k.imgepic.net");
//		head.put("Pragma", "no-cache");
//		head.put("RA-Sid", "73992FAC-20150508-121113-a60890-1c23f8");
//		head.put("RA-Ver", "2.10.4");
//		head.put("User-Agent", ua);
//		
//	}
	
	public MyJEditorPane() {
		super();
	}



	public MyJEditorPane(String type, String text) {
		super(type, text);
		// TODO Auto-generated constructor stub
	}



	public MyJEditorPane(String url) throws IOException {
		super(url);
		// TODO Auto-generated constructor stub
	}



	public MyJEditorPane(URL initialPage) throws IOException {
		super(initialPage);
		// TODO Auto-generated constructor stub
	}



	@Override
	protected InputStream getStream(URL page) throws IOException {
		
		return super.getStream(page);
//		final URLConnection conn = page.openConnection();
//        if (conn instanceof HttpURLConnection) {
//            HttpURLConnection hconn = (HttpURLConnection) conn;
//            
//            for(String key:head.keySet())
//            {
//            	conn.setRequestProperty(key, head.get(key));
//            }
//            conn.setRequestProperty("User-Agent",
//                    "ua");
//            conn.setRequestProperty("Accept",
//            		"image/webp,*/*;q=0.8");
//            conn.setRequestProperty("Connection",
//            		"keep-alive");
//            hconn.setInstanceFollowRedirects(false);
           
//            int response = hconn.getResponseCode();
//            boolean redirect = (response >= 300 && response <= 399);
//
//            /*
//             * In the case of a redirect, we want to actually change the URL
//             * that was input to the new, redirected URL
//             */
//            if (redirect) {
//                String loc = conn.getHeaderField("Location");
//                if (loc.startsWith("http", 0)) {
//                    page = new URL(loc);
//                } else {
//                    page = new URL(page, loc);
//                }
//                return getStream(page);
//            }
//        }
//
//        return conn.getInputStream();
	}
}
